﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Vision.Core.ActivityComponents.Converters
{
    /// <summary>
    /// 
    /// </summary>
    public class TypeOfConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is System.Activities.Presentation.Model.ModelItem)
            {
                if (parameter == null || parameter.ToString().ToLower() == "generic")
                    return (value as System.Activities.Presentation.Model.ModelItem).ItemType.GetGenericArguments().First();
                else if (parameter != null && parameter.ToString().ToLower() == "typeofcurrent")
                    return (value as System.Activities.Presentation.Model.ModelItem).GetCurrentValue();
                else
                    return value.GetType();
            }
            else if (value == null)
                return typeof(object);
            else
                return value.GetType();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
